#include <stdio.h>
#include <stdlib.h>
#include "tpm_measurement.h"

/*
 *   these are defined for test   
 *                                                                              
 */
 
#define COMPANY "xd"
#define BASE_PARAM "3.10GHz"
#define SERIAL_NUM "008"
#define SHA1_HASH_CPU "cpu sha1 result"

#define SOFT_NAME "vxworks"
#define VERSION "v32"
#define SHA1_HASH_SOFT "soft sha1 result"

STATUS initCPUStruct(PCPUINFO *pCpuStruct){
	STATUS flag = SUCCESS;
	*pCpuStruct = (PCPUINFO)calloc(1, sizeof(CPUINFO));
	if(*pCpuStruct == NULL){
		flag = FAIL;
		printf("malloc failed");
	}
	return flag;
}

STATUS fillCPUStruct(PCPUINFO cpuStruct){
	STATUS flag = SUCCESS;
	if (cpuStruct != NULL){
		strcpy(cpuStruct->Company, COMPANY);
		strcpy(cpuStruct->BaseParam, BASE_PARAM);
		strcpy(cpuStruct->SerialNumber, SERIAL_NUM);
		strcpy(cpuStruct->sha1_hash, SHA1_HASH_CPU);
	}	
	else{
		flag = FAIL;
	}
	return flag;
}

STATUS freeCPUStruct(PCPUINFO *pCpuStruct){
	STATUS flag = SUCCESS;
	if(*pCpuStruct != NULL){
		free(*pCpuStruct);
		*pCpuStruct = NULL;
	}
	else{
		flag = FAIL;
	}
	return flag;
}

/*
  function of softwate information
*/

STATUS initSoftStruct(PSOFTINFO *pSoftInfo){
	STATUS flag = SUCCESS;
	*pSoftInfo = (PSOFTINFO)calloc(1,sizeof(SOFTINFO));
	if(*pSoftInfo == NULL) {
		flag = FAIL;
	}
	return flag;
}

STATUS fillSoftStruct(PSOFTINFO softStruct){
	STATUS flag = SUCCESS;
		
	if(softStruct != NULL ){	
	
		strcpy(softStruct->softname, SOFT_NAME);
		strcpy(softStruct->version, VERSION);
		strcpy(softStruct->sha1_hash, SHA1_HASH_SOFT);		
	}
	else{
		flag = FAIL;
	}
	return flag;
}

STATUS freeSoftStruct(PSOFTINFO *pSoftInfo){
	STATUS flag = SUCCESS;
	if(*pSoftInfo != NULL) {
		free(*pSoftInfo);
		*pSoftInfo = NULL;
	}
	else {
		flag = FAIL;
	}
	return flag;
}

